<!--
 * @Descripttion: 
 * @version: 
 * @Author: wtzhang
 * @Date: 2021-10-25 13:33:25
 * @LastEditors: wtzhang
 * @LastEditTime: 2021-10-25 14:07:08
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>变量提升</title>
</head>

<body>
  <script>
    // 1. 变量的提升
    console.log(a); 
    var a = 1
    function test() {
      console.log(b);
      var b = 2
      console.log(b);
    }
    test()
    console.log(a);
    // undefined undefined 2 1
    
    // 2. 函数提升
    // 函数字面量式
    console.log(bar);
    var bar = function() {
      console.log(111);
    }
    /**
     * var bar;
     * console.log(bar)
     * bar = function(){ console.log('111');}
     */
    // 执行结果：undefined

    // 函数声明式
    console.log(bar2);
    function bar2() {
      console.log('222');
    }
    /*
    执行顺序实则：
    function bar2() {
      console.log('222');
    }
    console.log(bar2);
    */
    // 执行结果：
    // ƒ bar2() {
    //   console.log('222');
    // }

    // 实例：
    function bar3() {
      console.log(333);
    }
    var bar4 = function(){
      console.log(444);
    }
    bar3()
    
  </script>
</body>

</html>